package com.flyemu.share.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.lang.Assert;
import com.flyemu.share.annotation.SaAccountVal;
import com.flyemu.share.annotation.SaMerchantId;
import com.flyemu.share.dto.AccountDto;
import com.flyemu.share.entity.Project;
import com.flyemu.share.entity.Role;
import com.flyemu.share.service.ProjectService;
import com.flyemu.share.service.RoleService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @功能描述: 项目管理
 * @创建时间: 2023年08月08日
 * @公司官网: www.fenxi365.com
 * @公司信息: 纷析云（杭州）科技有限公司
 * @公司介绍: 专注于财务相关软件开发, 企业会计自动化解决方案
 */
@RestController
@RequestMapping("/project")
@RequiredArgsConstructor
@SaCheckLogin
public class ProjectController {

    private final ProjectService projectService;


    @GetMapping
    public JsonResult list(@SaAccountVal AccountDto accountDto, ProjectService.Query query) {
        query.setMerchantId(accountDto.getMerchantId());
        return JsonResult.successful(projectService.query(query));
    }


    @PostMapping
    public JsonResult save(@RequestBody @Valid Project project, @SaAccountVal AccountDto accountDto) {
        project.setMerchantId(accountDto.getMerchantId());
        projectService.save(project);
        return JsonResult.successful();
    }


    @PutMapping
    public JsonResult update(@RequestBody @Valid Project project, @SaAccountVal AccountDto accountDto) {
        project.setMerchantId(accountDto.getMerchantId());
        projectService.save(project);
        return JsonResult.successful();
    }

    @DeleteMapping("/{projectId}")
    public JsonResult delete(@PathVariable Integer projectId, @SaMerchantId Integer merchantId) {
        projectService.delete(projectId, merchantId);
        return JsonResult.successful();
    }
}
